package cn.huyanbing.visual.agent;

import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.jar.asm.commons.Method;

import java.util.concurrent.Callable;

/**
 * @BelongProject middleware
 * @BelongPackage cn.huyanbing.visual.agent
 * @Description TODO
 * @ClassName TimeInterceptor
 * @Author huyangbing
 * @Date 2025/2/8 17:15
 * @Version 1.0.0
 */
public class TimeInterceptor {
    @RuntimeType
    public static Object intercept(@Origin Method method,
                                   @SuperCall Callable<?> callable) throws Exception {
        long start = System.currentTimeMillis();
        try {
            // 原有函数执行
            return callable.call();
        } finally {
            System.out.println(method + ": took " + (System.currentTimeMillis() - start) + "ms");
        }
    }
}